home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / scsh-0.4 / scsh-0 / scsh-0.4.2 / scsh / flock1.c < prev    next >
C/C++ Source or Header  |  1995-10-22  |  1KB  |  42 lines

  1. /* Scheme48/scsh Unix system interface.
  2. ** Routines that require custom C support.
  3. ** Copyright (c) 1995 by David Albertz.
  4. */
  5.  
  6. /*  File locking routines  */
  7.  
  8. #include <sys/types.h>
  9. #include <unistd.h>
  10. #include <fcntl.h>
  11.  
  12. /* Make sure our exports match up w/the implementation: */
  13. #include "flock1.h"
  14.  
  15. int set_lock(int fd, int cmd, int type, int whence, int start, int len)
  16. {
  17.     struct flock lock;
  18.     lock.l_type   = type;
  19.     lock.l_whence = whence;
  20.     lock.l_start  = start;
  21.     lock.l_len    = len;
  22.     return(fcntl(fd, cmd, &lock));
  23.     }
  24.  
  25. int get_lock(int fd, int cmd, int type, int whence, int start, int len,
  26.          int *rtype, int *rwhence, int *rstart, int *rlen, int *rpid)
  27. {
  28.     struct flock lock;
  29.     int ret;
  30.     lock.l_type   = type;
  31.     lock.l_whence = whence;
  32.     lock.l_start  = start;
  33.     lock.l_len    = len;
  34.     ret = fcntl(fd, F_GETLK, &lock);
  35.     *rtype = lock.l_type;
  36.     *rwhence = lock.l_whence;
  37.     *rstart = lock.l_start;
  38.     *rlen = lock.l_len;
  39.     *rpid = lock.l_pid;
  40.     return(ret);
  41.     }
  42.